<template>
	<view>
		<view class="rx_detail">
			<view class="top" v-if="rp_doctor">
				<view class="acea-row row-between-wrapper">
					<view>医生：{{ rp_doctor.nickname }}</view>
				</view>
			</view>
			<view class="medical_list" v-if="rp_products">
				<view class="medical_top acea-row row-between-wrapper">
					<view>药品列表</view>
					<view class="num font-color">共{{ rp_products.length }}件</view>
				</view>
				<view class="item" v-for="(item, index) in rp_products" :key="index">
					<view class="name acea-row row-between-wrapper">
						<view>{{ item.cart_info.product.store_name }}</view>
						<view>数量：{{ item.product_num }}</view>
					</view>
				</view>
			</view>
			<view class="rp_info">
				<view class="prescription acea-row row-between-wrapper">
					<view>处方笺</view>
					<button @click="checkPrescription" v-if="rp_urls && rp_urls.length>0">查看处方</button>
					<view v-else style="color: #969696;font-size: 24rpx;">暂无处方</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var _self;
	import {
		getPrescribeDetail
	} from '@/api/user.js'
	export default {
		data() {
			return {
				order_id: '',
				rp_info: null,
				rp_doctor:null,
				rp_products:null,
				rp_urls:null,
			};
		},
		onLoad(options) {
			_self = this;
			if (options.order_id) {
				_self.order_id = options.order_id;
				_self.getInfo();
			} else {
				return _self.$util.Tips({
					title: '缺少参数无法查看'
				}, {
					tab: 3,
					url: 1
				});
			}
		},
		methods: {
			getInfo() {
				getPrescribeDetail(_self.order_id).then(res => {
					let data = res.data;
					_self.rp_doctor = data.doctor;
					_self.rp_products = data.products;
					_self.rp_urls = data.rp_url;
				}).catch(err => {
					return _self.$util.Tips({
						title: err
					});
				});
			},
			// 查看處方
			checkPrescription() {
				if(this.rp_urls.length<=0){
					return this.$util.Tips({title:'处方信息不存在'});
				}
				// 图片处方
				// uni.previewImage({
				// 	urls:this.rp_urls
				// })
				
				// rk_pdf 处方
				let pdf_rpurl = this.rp_urls[0];
				let url = encodeURIComponent(JSON.stringify(pdf_rpurl));
				uni.navigateTo({
					url: "/pages/rp/rp_pdfs/rp_pdfs?move_url=" + url,
				})
				
			},
		}
	};
</script>

<style lang="scss" scoped>
	.top {
		background: #fff;
		font-size: 28rpx;
		line-height: 1;
		padding: 28rpx 28rpx 40rpx 28rpx;

		.row-between-wrapper {
			padding: 28rpx 0 0;
		}

		.info {
			.info_detail {
				padding-top: 35rpx;
				line-height: 1.3;
			}

			.info_num {
				color: #969696;
				margin-top: 20rpx;
				font-size: 24rpx;
			}
		}
	}

	.medical_list {
		background: #fff;
		padding: 0 28rpx 20rpx;
		margin-top: 10rpx;

		.medical_top {
			padding: 35rpx 0 30rpx 0;
			border-bottom: solid 1px #f5f5f5;
		}

		.item {
			line-height: 1;

			.name {
				view {
					&:first-child {
						// font-weight: bold;
						margin-bottom: 10rpx;
					}
				}

				margin-top: 35rpx;
			}

			.text {
				margin-top: 25rpx;
				padding-bottom: 20rpx;
				border-bottom: solid 1px #f5f5f5;

				text {
					color: #969696;
				}
			}
		}

	}
	.rp_info {
		background: #fff;
		padding: 20rpx 28rpx;
		margin-top: 10rpx;
		.prescription {
			padding: 28rpx 0;
			button {
				padding: 15rpx 30rpx;
				border-radius: 30rpx;
				background: #e93323;
				font-size: 24rpx;
				color: #fff;
			}
		}
	}
	
</style>